def isPal(n) :
	return str(n) == str(n)[::-1]

def reverseAdd(n) :
	return n + int(str(n)[::-1])

def isLychrel(n, lychrel, depth=0) :
	try :
		if not lychrel[n] :
			return False
	except KeyError :
		pass
	if depth > 50 :
		return True
	n2 = reverseAdd(n)
	if isPal(n2) :
		lychrel[n] = False
		return False
	if not isLychrel(n2, lychrel, depth + 1) :
		lychrel[n] = False
		return False
	return True

lychrel = {}
l = []
for n in range(10000) :
	lychrel[n] = True

for n in range(10000) :
	if isLychrel(n, lychrel) :
		l.append(n)
	print n

print "l", l
print "len(l)", len(l)